/*
 * Project 1 phase 1
 * Efim Todorasco and Liviu Patrasco  
 */
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;



public class GUI {
	public static JFrame appFrame;
	GLCanvas canvas;
	public GUI () {
		Scene s = new Scene();
		canvas = s.getCanvas();
	}
	public static void main(String[] args) {
		GLProfile.initSingleton();
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				(new GUI()).createAndShowGUI();
			}
		});
	}
	protected void createAndShowGUI() {
		
		appFrame = new JFrame("Scene");
		appFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		appFrame.setMinimumSize(new Dimension(400, 400));
		appFrame.add(canvas);
		appFrame.setJMenuBar(createMenuBar());
		appFrame.pack();
		if (Toolkit.getDefaultToolkit().isFrameStateSupported(JFrame.MAXIMIZED_BOTH))
			appFrame.setExtendedState(appFrame.getExtendedState() | JFrame.MAXIMIZED_BOTH);
		appFrame.setVisible(true);
	}
	private JMenuBar createMenuBar() {
		ArrayList<JMenuItem> menuItem = new ArrayList<JMenuItem>();
		JMenuBar menuBar = new JMenuBar();
		JMenu addMenu = new JMenu("New...");
		JMenu addMenu2 = new JMenu("Help");
		JMenuItem item = new JMenuItem("About");
		menuItem.add(new JMenuItem("Triangle"));
		menuItem.add(new JMenuItem("Circle"));
		menuItem.add(new JMenuItem("Rectangle"));
		menuItem.add(new JMenuItem("Ellipse"));
		menuItem.add(new JMenuItem("Paddle"));
		menuItem.add(new JMenuItem("Tree"));
		menuItem.get(0).addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Scene.sceneGraphRoot.addChild(new Triangle2());
				Scene.displayListID = -1;
			}
		});
		menuItem.get(1).addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Scene.sceneGraphRoot.addChild(new Circle());
				Scene.displayListID = -1;
			}
		});
		menuItem.get(2).addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Scene.sceneGraphRoot.addChild(new Rectangle());
				Scene.displayListID = -1;
			}
		});
		menuItem.get(3).addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Scene.sceneGraphRoot.addChild(new Ellipse());
				Scene.displayListID = -1;
			}
		});
		menuItem.get(4).addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Scene.sceneGraphRoot.addChild(new Paddle());
				Scene.displayListID = -1;
			}
		});
		menuItem.get(5).addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Scene.sceneGraphRoot.addChild(Tree.create(8));
				Scene.displayListID = -1;
			}
		});
		item.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JOptionPane.showMessageDialog(null, "explore: awsd\nscale in: +\nscale out: -\nrotate left: c\nrotate right: v\nremove: r\nzoom out: z\nzoom in: x");
			}
		});

		addMenu2.add(item);
		for (int i = 0; i < menuItem.size(); i++) {
		addMenu.add(menuItem.get(i));
		}
		menuBar.add(addMenu);
		menuBar.add(addMenu2);

		return menuBar;
	}
	
}
